package com.hg.common;

import java.io.Serializable;

/**
 * 响应信息主体
 *
 * @param <T>
 * @author lengleng
 */
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int FAIL = -1;

    public static final int SUCCESS = 1;

    public static final int TOKEN_EXPIRE = 1000;

    public static final int ERROR_NO_COUPON_FOR_COURSE = 2001;

    private String msg = "success";

    private int code = SUCCESS;

    private T data;

    public static R success() {
        R r = new R();
        r.setCode(SUCCESS);
        r.setData(null);
        r.setMsg("success");
        return r;
    }

    public static R success(Object data) {
        R r = new R();
        r.setCode(SUCCESS);
        r.setData(data);
        r.setMsg("success");
        return r;
    }

    public static R fail(int code,String msg) {
        R r = new R();
        r.setCode(code);
        r.setData(null);
        r.setMsg(msg);
        return r;
    }


    public R() {
        super();
    }

    public R(T data) {
        super();
        this.data = data;
    }

    public R(T data, String msg) {
        super();
        this.data = data;
        this.msg = msg;
    }

    public R(T data, int code, String msg) {
        super();
        this.data = data;
        this.msg = msg;
        this.code = code;
    }

    public R(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public R(Throwable e) {
        super();
        this.msg = e.getMessage();
        this.code = FAIL;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
